﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using TSL_Tools.SqlTools;
using ReportingEngine;
using System.IO;
using System.Text.RegularExpressions;
using ReportGenerator;

namespace VSLT_Reporting
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        #region -- Main Generate data Methods ----------------------------------------------------------------------------
        private void GenerateRunData_TEST()
        {
            bool byInterval = (bool)btnToggleUseIntervals.IsChecked;
            //bool useDetailedTiming = Properties.Settings.Default.UseDetailedTimingsForTablesWhenAvailable;
            bool detailedTimingAvailable = re.listOfRuns[currentlyHighlightedRunId].resultTypes.HasFlag(ResultTypesStoredInLoadTest.ContainsDetailedTimingInfo);

            
            DataTable _table = new DataTable();
            tabDataGrid.IsSelected = true;
            if (byInterval && detailedTimingAvailable)
                if (intervalColumnSelectedValue.SelectedValue.ToString().ToLower() == "throughput")
                {
                    MessageBox.Show("Test Throughout calculations currently not implemented", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    GenerateRunData_interval(TSL_ReportingEngine.Sql_INTERVAL_TESTRESULTS, "Test Name");
                }
            else
                GenerateRunData(TSL_ReportingEngine.Sql_SUMMARY_TESTRESULTS, ref _table, false, "Test Name");
        }

        private void GenerateRunData_TRANSACTION()
        {
            bool byInterval = (bool)btnToggleUseIntervals.IsChecked;
            bool detailedTimingAvailable = re.listOfRuns[currentlyHighlightedRunId].resultTypes.HasFlag(ResultTypesStoredInLoadTest.ContainsDetailedTimingInfo);

            DataTable _table = new DataTable();
            tabDataGrid.IsSelected = true;
            if (byInterval && detailedTimingAvailable)
                if (intervalColumnSelectedValue.SelectedValue.ToString().ToLower() == "throughput")
                {
                    MessageBox.Show("Transaction Throughout calculations currently not implemented", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    GenerateRunData_interval(TSL_ReportingEngine.Sql_INTERVAL_TRANSACTIONRESULTS, "Transaction Name");
                }
            else
                GenerateRunData(TSL_ReportingEngine.Sql_SUMMARY_TRANSACTIONRESULTS, ref _table, false, "Transaction Name");
        }

        private void GenerateRunData_PAGE()
        {
            bool byInterval = (bool)btnToggleUseIntervals.IsChecked;
            bool detailedTimingAvailable = re.listOfRuns[currentlyHighlightedRunId].resultTypes.HasFlag(ResultTypesStoredInLoadTest.ContainsDetailedTimingInfo);

            DataTable _table = new DataTable();
            tabDataGrid.IsSelected = true;
            if (byInterval && detailedTimingAvailable)
                if (intervalColumnSelectedValue.SelectedValue.ToString().ToLower() == "throughput")
                {
                    GenerateRunThroughputData_interval(TSL_ReportingEngine.Sql_INTERVAL_PAGETHROUGHPUT, "Page Name");
                }
                else
                {
                    GenerateRunData_interval(TSL_ReportingEngine.Sql_INTERVAL_PAGERESULTS, "Page Name");
                }
            else
                GenerateRunData(TSL_ReportingEngine.Sql_SUMMARY_PAGERESULTS, ref _table, false, "Page Name");
            
            //AddPageTableToReportTab();

        }

        private void AddPageTableToReportTab()
        {
            DataTable _table = dgRunResults.ItemsSource as DataTable;
            
            CellHighlighting highlighting = new CellHighlighting();
            highlighting.threshold1 = 0.01;
            highlighting.threshold2 = 0.1;
            highlighting.threshold3 = 0.5;
            highlighting.threshold4 = 1;

            Typeface font = new Typeface("Arial");
            FlowDocument flowDocTemp = TSL_ReportGenerator.CreateXamlTableFromDataTable("HotSpot Table", _table, font, 12, highlighting);

            rtbResults.Document.Blocks.Add(flowDocTemp.Blocks.FirstBlock);
            rtbResults.Document.Blocks.Add(ReportGenerator.TSL_ReportGenerator.AddSeparatorLineToReport().Blocks.FirstBlock);
            rtbResults.UpdateLayout();
        }

        private void AddPageTableToReportTab(DataTable _table, CellHighlighting highlighting, string name)
        {

            Typeface font = new Typeface("Arial");
            FlowDocument flowDocTemp = TSL_ReportGenerator.CreateXamlTableFromDataTable(name, _table, font, 12, highlighting);

            rtbResults.Document.Blocks.Add(flowDocTemp.Blocks.FirstBlock);
            rtbResults.Document.Blocks.Add(ReportGenerator.TSL_ReportGenerator.AddSeparatorLineToReport().Blocks.FirstBlock);
            rtbResults.UpdateLayout();
        }

        private void GenerateRunData_TRANSACTION_COMBINED()
        {
            Cursor _cursor = this.Cursor;
            this.Cursor = Cursors.Wait;
            tabDataGrid.IsSelected = true;
            int includeFailedPages = (bool)btnToggleIncludeFailed.IsChecked ? 1 : 0;
            int includeWarmup = (bool)btnToggleIncludeWarmup.IsChecked ? 1 : 0;
            bool byInterval = (bool)btnToggleUseIntervals.IsChecked;
            int numRows = 0;

            string sqlCmd = String.Format(TSL_ReportingEngine.Sql_TRANSACTIONRESULTS_GROUPEDBYNAME, 
                currentlyHighlightedRunId, 
                tbTableFilterString.Text,
                "NULL", 
                "NULL", 
                0, 
                0, 
                includeWarmup, 
                Properties.Settings.Default.numTopSlowest);
            DataTable _table;
            TalkToSql tts = new TalkToSql(re.sqlConn, Properties.Settings.Default.ConnectionTimeout, Properties.Settings.Default.CommandTimeout);
            TimeSpan ts = tts.ExecuteReaderTable(sqlCmd, out _table);
            mostRecentSqlQuery = sqlCmd;
            dgRunResults.ItemsSource = _table.AsDataView();
            numRows = _table.Rows.Count;
            this.Cursor = _cursor;
            tsslMessage.Content = String.Format("{0} rows returned", numRows);
        }

        private void GenerateRunData_PAGE_COMBINED()
        {
            Cursor _cursor = this.Cursor;
            this.Cursor = Cursors.Wait;
            tabDataGrid.IsSelected = true;
            int includeFailedPages = (bool)btnToggleIncludeFailed.IsChecked ? 1 : 0;
            int includeWarmup = (bool)btnToggleIncludeWarmup.IsChecked ? 1 : 0;
            bool byInterval = (bool)btnToggleUseIntervals.IsChecked;
            int numRows = 0;

            //if (byInterval)
            //{
            //    int intervalSpan;
            //    Int32.TryParse(tbIntervalValue.Text, out intervalSpan);
            //}
            //else
            //{
                string sqlCmd = String.Format(TSL_ReportingEngine.Sql_PAGERESULTS_GROUPEDBYNAME, currentlyHighlightedRunId, tbTableFilterString.Text,
                    "NULL", "NULL", includeFailedPages, 0, includeWarmup, "NULL", Properties.Settings.Default.numTopSlowest);
                DataTable _table;
                TalkToSql tts = new TalkToSql(re.sqlConn, Properties.Settings.Default.ConnectionTimeout, Properties.Settings.Default.CommandTimeout);
                TimeSpan ts = tts.ExecuteReaderTable(sqlCmd, out _table);
                mostRecentSqlQuery = sqlCmd;
                dgRunResults.ItemsSource = _table.AsDataView();
                numRows = _table.Rows.Count;
            //}
            this.Cursor = _cursor;
            tsslMessage.Content = String.Format("{0} rows returned", numRows);
        }

        private void GenerateRunData_PERFMON()
        {
            Cursor _cursor = this.Cursor;
            this.Cursor = Cursors.Wait;
            this.Cursor = _cursor;

        }
        #endregion

        #region -- Timing Generation Routines ----------------------------------------------------------------------------
        private void GenerateRunData(string sqlQuery, ref DataTable _table, bool addToReport, string columnName)
        {
            Cursor _cursor = this.Cursor;
            this.Cursor = Cursors.Wait;
            int includeFailed = (bool)btnToggleIncludeFailed.IsChecked ? 1 : 0;
            int includeWarmup = (bool)btnToggleIncludeWarmup.IsChecked ? 1 : 0;
            int numRows = 0;

            string sqlCmd = String.Format(sqlQuery, currentlyHighlightedRunId, tbTableFilterString.Text,
                "NULL", "NULL", includeFailed, 1, includeWarmup, Properties.Settings.Default.numTopSlowest);
            TalkToSql tts = new TalkToSql(re.sqlConn, Properties.Settings.Default.ConnectionTimeout, Properties.Settings.Default.CommandTimeout);
            TimeSpan ts = tts.ExecuteReaderTable(sqlCmd, out _table);
            AddDebugTimingInfo(ts, "--GenerateRunData  " + sqlCmd);
            mostRecentSqlQuery = sqlCmd;
            if (!addToReport)
                dgRunResults.ItemsSource = _table.AsDataView();
            numRows = _table.Rows.Count;
            this.Cursor = _cursor;
            tsslMessage.Content = String.Format(Msg_ROWSRETURNED, numRows);
            CopyRunResultsTableToClipboard();

        }

        private TimeSpan GenerateRunData_interval(string baseSqlCmd, string columnName)
        {
            DateTime dt = DateTime.Now;
            Cursor _cursor = this.Cursor;
            this.Cursor = Cursors.Wait;
            tabDataGrid.IsSelected = true;
            int includeFailedPages = (bool)btnToggleIncludeFailed.IsChecked ? 1 : 0;
            int includeWarmup = (bool)btnToggleIncludeWarmup.IsChecked ? 1 : 0;
            bool byInterval = (bool)btnToggleUseIntervals.IsChecked;
            int numRows = 0;

            #region Get The Intervals
            List<int[]> intervals = new List<int[]>();
            if (tbIntervalValue.Text != "")
            {
                // -- An interval value was entered. Use that to build the results
                int intervalSpan;
                Int32.TryParse(tbIntervalValue.Text, out intervalSpan);
                int testDuration = re.listOfRuns[currentlyHighlightedRunId].duration;

                for (int intervalStart = 0; intervalStart < testDuration; intervalStart += intervalSpan)
                {
                    /// Enter the beginning value, ending value, the user count, and the number of samples for the interval.
                    intervals.Add(new int[] { intervalStart, intervalStart + intervalSpan, 0, 0 });
                }

            }
            else
            {
                re.GetConstantLoadIntervals(out intervals, currentlyHighlightedRunId);
            }
            #endregion

            DataTable finalTable = new DataTable();
            bool addNameColumn = true;

            foreach (int[] interval in intervals)
            {
                string sqlCmd = String.Format(baseSqlCmd, currentlyHighlightedRunId, tbTableFilterString.Text,
                    interval[0], interval[1], includeFailedPages, 0, includeWarmup, Properties.Settings.Default.numTopSlowest);
                DataTable _table;
                TalkToSql tts = new TalkToSql(re.sqlConn, Properties.Settings.Default.ConnectionTimeout, Properties.Settings.Default.CommandTimeout);
                tts.ExecuteReaderTable(sqlCmd, out _table);
                mostRecentSqlQuery = sqlCmd;
                if (addNameColumn)
                {
                    AddNameColumnsToExistingTable(ref _table, ref finalTable, "Name", columnName);
                    addNameColumn = false;
                }
                string valueColumnName = String.Format("{0} users\r\n{1}-{2} sec\r\n{3} Time"
                    , interval[2], interval[0], interval[1], intervalColumnSelectedValue.SelectedValue.ToString());
                AddColumnsToExistingTable(ref _table, ref finalTable, intervalColumnSelectedValue.SelectedValue.ToString(), valueColumnName);
            }
            dgRunResults.ItemsSource = finalTable.AsDataView();
            numRows = finalTable.Rows.Count;

            this.Cursor = _cursor;
            tsslMessage.Content = String.Format("{0} rows returned for {1} values", numRows, intervalColumnSelectedValue.SelectedValue.ToString());
            CopyRunResultsTableToClipboard();

            return (TimeSpan)(DateTime.Now - dt);
        }

        private DataTable GenerateRunData_interval_ReturnAsTable(string baseSqlCmd, string columnName, ref TimeSpan timeToProcess)
        {
            DateTime dt = DateTime.Now;
            Cursor _cursor = this.Cursor;
            this.Cursor = Cursors.Wait;
            //tabDataGrid.IsSelected = true;
            int includeFailedPages = (bool)btnToggleIncludeFailed.IsChecked ? 1 : 0;
            int includeWarmup = (bool)btnToggleIncludeWarmup.IsChecked ? 1 : 0;
            bool byInterval = (bool)btnToggleUseIntervals.IsChecked;

            #region Get The Intervals
            List<int[]> intervals = new List<int[]>();
            if (tbIntervalValue.Text != "")
            {
                // -- An interval value was entered. Use that to build the results
                int intervalSpan;
                Int32.TryParse(tbIntervalValue.Text, out intervalSpan);
                int testDuration = re.listOfRuns[currentlyHighlightedRunId].duration;

                for (int intervalStart = 0; intervalStart < testDuration; intervalStart += intervalSpan)
                {
                    /// Enter the beginning value, ending value, the user count, and the number of samples for the interval.
                    intervals.Add(new int[] { intervalStart, intervalStart + intervalSpan, 0, 0 });
                }

            }
            else
            {
                re.GetConstantLoadIntervals(out intervals, currentlyHighlightedRunId);
            }
            #endregion

            DataTable finalTable = new DataTable();
            bool addNameColumn = true;

            foreach (int[] interval in intervals)
            {
                string sqlCmd = String.Format(baseSqlCmd, currentlyHighlightedRunId, tbTableFilterString.Text,
                    interval[0], interval[1], includeFailedPages, 0, includeWarmup, Properties.Settings.Default.numTopSlowest);
                DataTable _table;
                TalkToSql tts = new TalkToSql(re.sqlConn, Properties.Settings.Default.ConnectionTimeout, Properties.Settings.Default.CommandTimeout);
                tts.ExecuteReaderTable(sqlCmd, out _table);
                mostRecentSqlQuery = sqlCmd;
                if (addNameColumn)
                {
                    AddNameColumnsToExistingTable(ref _table, ref finalTable, "Name", columnName);
                    addNameColumn = false;
                }
                string valueColumnName = String.Format("{0} users\r\n{1}-{2} sec\r\n{3} Time"
                    , interval[2], interval[0], interval[1], intervalColumnSelectedValue.SelectedValue.ToString());
                AddColumnsToExistingTable(ref _table, ref finalTable, intervalColumnSelectedValue.SelectedValue.ToString(), valueColumnName);
            }
            this.Cursor = _cursor;
            timeToProcess = (TimeSpan)(DateTime.Now - dt);
            return finalTable;
        }

        private TimeSpan GenerateRunThroughputData_interval(string baseSqlCmd, string columnName)
        {
            DateTime dt = DateTime.Now;
            Cursor _cursor = this.Cursor;
            this.Cursor = Cursors.Wait;
            tabDataGrid.IsSelected = true;
            int numRows = 0;

            #region Get The Intervals
            List<int[]> intervals = new List<int[]>();
            if (tbIntervalValue.Text != "")
            {
                // -- An interval value was entered. Use that to build the results
                int intervalSpan;
                Int32.TryParse(tbIntervalValue.Text, out intervalSpan);
                int testDuration = re.listOfRuns[currentlyHighlightedRunId].duration;

                for (int intervalStart = 0; intervalStart < testDuration; intervalStart += intervalSpan)
                {
                    /// Enter the beginning value, ending value, the user count, and the number of samples for the interval.
                    intervals.Add(new int[] { intervalStart, intervalStart + intervalSpan, 0, 0 });
                }

            }
            else
            {
                re.GetConstantLoadIntervals(out intervals, currentlyHighlightedRunId);
            }
            #endregion

            DataTable finalTable = new DataTable();
            bool addNameColumn = true;

            foreach (int[] interval in intervals)
            {
                string sqlCmd = String.Format(baseSqlCmd, currentlyHighlightedRunId, tbTableFilterString.Text,
                    interval[0], interval[1], Properties.Settings.Default.numTopSlowest);
                DataTable _table;
                TalkToSql tts = new TalkToSql(re.sqlConn, Properties.Settings.Default.ConnectionTimeout, Properties.Settings.Default.CommandTimeout);
                tts.ExecuteReaderTable(sqlCmd, out _table);
                mostRecentSqlQuery = sqlCmd;
                if (addNameColumn)
                {
                    AddNameColumnsToExistingTable(ref _table, ref finalTable, "Name", columnName);
                    addNameColumn = false;
                }
                string valueColumnName = String.Format("{0} users\r\n{1}-{2} sec\r\n{3}"
                    , interval[2], interval[0], interval[1], intervalColumnSelectedValue.SelectedValue.ToString());
                AddColumnsToExistingTable(ref _table, ref finalTable, intervalColumnSelectedValue.SelectedValue.ToString(), valueColumnName);
            }
            dgRunResults.ItemsSource = finalTable.AsDataView();
            numRows = finalTable.Rows.Count;

            this.Cursor = _cursor;
            tsslMessage.Content = String.Format("{0} rows returned for {1} values", numRows, intervalColumnSelectedValue.SelectedValue.ToString());
            CopyRunResultsTableToClipboard();

            return (TimeSpan)(DateTime.Now - dt);
        }

        private DataTable GenerateRunThroughputData_interval_ReturnAsTable(string baseSqlCmd, string columnName, ref TimeSpan timeToProcess)
        {
            DateTime dt = DateTime.Now;
            Cursor _cursor = this.Cursor;
            this.Cursor = Cursors.Wait;
            int numRows = 0;

            #region Get The Intervals
            List<int[]> intervals = new List<int[]>();
            if (tbIntervalValue.Text != "")
            {
                // -- An interval value was entered. Use that to build the results
                int intervalSpan;
                Int32.TryParse(tbIntervalValue.Text, out intervalSpan);
                int testDuration = re.listOfRuns[currentlyHighlightedRunId].duration;

                for (int intervalStart = 0; intervalStart < testDuration; intervalStart += intervalSpan)
                {
                    /// Enter the beginning value, ending value, the user count, and the number of samples for the interval.
                    intervals.Add(new int[] { intervalStart, intervalStart + intervalSpan, 0, 0 });
                }

            }
            else
            {
                re.GetConstantLoadIntervals(out intervals, currentlyHighlightedRunId);
            }
            #endregion

            DataTable finalTable = new DataTable();
            bool addNameColumn = true;

            foreach (int[] interval in intervals)
            {
                string sqlCmd = String.Format(baseSqlCmd, currentlyHighlightedRunId, tbTableFilterString.Text,
                    interval[0], interval[1], Properties.Settings.Default.numTopSlowest);
                DataTable _table;
                TalkToSql tts = new TalkToSql(re.sqlConn, Properties.Settings.Default.ConnectionTimeout, Properties.Settings.Default.CommandTimeout);
                tts.ExecuteReaderTable(sqlCmd, out _table);
                mostRecentSqlQuery = sqlCmd;
                if (addNameColumn)
                {
                    AddNameColumnsToExistingTable(ref _table, ref finalTable, "Name", columnName);
                    addNameColumn = false;
                }
                string valueColumnName = String.Format("{0} users\r\n{1}-{2} sec\r\n{3}"
                    , interval[2], interval[0], interval[1], intervalColumnSelectedValue.SelectedValue.ToString());
                AddColumnsToExistingTable(ref _table, ref finalTable, intervalColumnSelectedValue.SelectedValue.ToString(), valueColumnName);
            }
            numRows = finalTable.Rows.Count;

            this.Cursor = _cursor;
            timeToProcess = (TimeSpan)(DateTime.Now - dt);
            return finalTable;
        }
        #endregion

        #region -- DataTable Routines ----------------------------------------------------------------------------
        private void AddNameColumnsToExistingTable(ref DataTable sourceTable, ref DataTable destTable, string srcColumnName, string destColumnName)
        {
            destTable.Columns.Add("id");
            destTable.Columns.Add(destColumnName);
            if (destTable.Rows.Count == 0) // No data. Need to ADD the rows
            {
                for (int x = 0; x < sourceTable.Rows.Count; x++)
                    destTable.Rows.Add(sourceTable.Rows[x][0], sourceTable.Rows[x][srcColumnName]);
            }
        }

        private void AddColumnsToExistingTable(ref DataTable sourceTable, ref DataTable destTable, string srcColumnName, string destColumnName)
        {
            destTable.Columns.Add(destColumnName);
            if (destTable.Rows.Count == 0) // No data. Need to ADD the rows
            {
                throw new Exception("Error in building the interval timings: " + srcColumnName);
            }
            else
            {
                try
                {
                    for (int x = 0; x < sourceTable.Rows.Count; x++)
                    {
                        int destTableRowNum = GetRowNumberForEntry(ref destTable, 0, sourceTable.Rows[x][0].ToString());
                        if (destTableRowNum != -1)
                            destTable.Rows[destTableRowNum][destColumnName] = sourceTable.Rows[x][srcColumnName];
                        else
                        {
                            destTable.Rows.Add(sourceTable.Rows[x][0]);
                            destTable.Rows[sourceTable.Rows.Count - 1][destColumnName] = sourceTable.Rows[x][srcColumnName];
                        }
                    }
                }
                catch(IndexOutOfRangeException ex)
                {
                    Console.Write(ex.ToString());
                }
            }
        }

        private int GetRowNumberForEntry(ref DataTable _table, int column, string comparator)
        {         
            for (int x = 0; x < _table.Rows.Count; x++)
            {
                if (_table.Rows[x][column].ToString() == comparator)
                    return x;
            }

            return -1;
        }
        #endregion

        #region -- Button and General Routines ---------------------------------------------------------------------------
        private void CombineNamesButtonToggled()
        {
            if ((bool)btnToggleCombineNames.IsChecked)
            {
                btnGenTest.IsEnabled = false;
            }
            else
            {
                btnGenTest.IsEnabled = true;
            }
        }

        private void IncludeFailedIterationsButtonToggled()
        {
            if ((bool)btnToggleIncludeFailed.IsChecked)
            {
                btnGenTransaction.IsEnabled = false;
            }
            else
            {
                btnGenTransaction.IsEnabled = true;
            }
        }
        #endregion

        #region -- ScoreCard DataTable Routines -------------------------------------------------------------------------
        //private DataTable GenerateRunData_Scorecard_ReturnAsTable(string baseSqlCmd, string columnName, ref TimeSpan timeToProcess)
        //{
        //    DateTime dt = DateTime.Now;
        //    Cursor _cursor = this.Cursor;
        //    this.Cursor = Cursors.Wait;
        //    //tabDataGrid.IsSelected = true;
        //    int includeFailedPages = (bool)btnToggleIncludeFailed.IsChecked ? 1 : 0;
        //    int includeWarmup = (bool)btnToggleIncludeWarmup.IsChecked ? 1 : 0;
        //    bool byInterval = (bool)btnToggleUseIntervals.IsChecked;

        //    #region Get The Intervals
        //    for (int x = 1; x < selectedRuns.Count; x++)
        //    {
        //        table2 = re.GetSummaryTimingResultsForReportAsTable(selectedRuns[x], bUsePerfmon);
        //        _scoreCardMetrics.Merge(table2);
        //        table2.Rows.Clear();
        //        table2.Columns.Clear();
        //    }

        //    #endregion

        //    DataTable finalTable = new DataTable();
        //    bool addNameColumn = true;

        //    for (int x = 0; x < selectedRuns.Count; x++)
        //    {
        //        string sqlCmd = String.Format(baseSqlCmd, currentlyHighlightedRunId, tbTableFilterString.Text,
        //            interval[0], interval[1], includeFailedPages, 0, includeWarmup, Properties.Settings.Default.numTopSlowest);
        //        DataTable _table;
        //        TalkToSql tts = new TalkToSql(re.sqlConn, Properties.Settings.Default.ConnectionTimeout, Properties.Settings.Default.CommandTimeout);
        //        tts.ExecuteReaderTable(sqlCmd, out _table);
        //        mostRecentSqlQuery = sqlCmd;
        //        if (x == 0)
        //        {
        //            AddNameColumnsToExistingTable(ref _table, ref finalTable, "Name", columnName);
        //            addNameColumn = false;
        //        }
        //        string valueColumnName = String.Format("{0} users\r\n{1}-{2} sec\r\n{3} Time"
        //            , interval[2], interval[0], interval[1], intervalColumnSelectedValue.SelectedValue.ToString());
        //        AddColumnsToExistingTable(ref _table, ref finalTable, intervalColumnSelectedValue.SelectedValue.ToString(), valueColumnName);
        //    }
        //    this.Cursor = _cursor;
        //    timeToProcess = (TimeSpan)(DateTime.Now - dt);
        //    return finalTable;
        //}
        #endregion
    }
}


